package com.wxit.minio.demo;


import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import io.minio.errors.*;
import lombok.val;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class FileUploader {
    public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        var minioClient = MinioClient.builder()
                .endpoint("http://172.30.0.171:9000")
                .credentials("admin", "12345678")
                .build();

        //创建bucket
        String bucketName = "xiaohao";
        val exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
        if (!exists){
            //不存在，创建bucket
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
        }
        //上传文件
        minioClient.uploadObject(UploadObjectArgs.builder().bucket(bucketName).object("155上已使用的IP.md")
                .filename("C:\\Users\\Administrator\\Desktop\\工作笔记\\155上已使用的IP.md").build());
        System.out.println("文件上传成功");


    }
}
